package com.dawn.system.enter.web.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

import com.dawn.commons.web.controller.BaseController;
import com.dawn.commons.web.model.AjaxResponse;
import com.dawn.system.sys.service.UserService;

@Controller
@RequestMapping("/login")
public class LoginController extends BaseController {
	
	@Autowired
	private UserService userService ;
	
	@RequestMapping(value={"", "/{login;?.*}"}, method=RequestMethod.GET)
	public String login() {
		return "login" ;
	}

	/**
	 * 验证登录
	 * @return
	 */
	@RequestMapping(value="/loginValid", method=RequestMethod.POST)
	@ResponseBody
	public AjaxResponse loginCheck(String account, String password, Model model) {
		AjaxResponse ajaxResponse = this.userService.loginValidate(account, password) ;
		
		
		if(ajaxResponse.getStatus()) {
			
			
			return ajaxResponse ;
		} else {
			return ajaxResponse ;
		}
	}
	
	
	/** 
     * 用户登出 
     */  
    @RequestMapping("/logout")  
    public String logout(HttpServletRequest request){  
         return InternalResourceViewResolver.REDIRECT_URL_PREFIX + "/login";  
    } 
	
}
